const state = {
  agent: new Array(),
  agentSelectModel: ''
}
const mutations = {
  SET_AGENT: (state, data) => {
    try {
      for (let i = 0; i < state.agent.length; i++) {
        if (state.agent[i].id == data.id) {
            state.agent.splice(i, 1)
        }
      }
    } catch (e) {
    }
      state.agent.push(data)
  },
  SET_AGENT_SELECT_MODEL: (state, data) => {
      state.agentSelectModel=data
  },
  CLEAN_AGENT: (state) => {
    state.agent = new Array()
    state.agentSelectModel=''
  },
  CLEAN_AGENT_DATA: (state) => {
    state.agent = new Array()
  }
}

const actions = {
  // 设置代理等级
  setAgent({ commit }, data) {
    commit('SET_AGENT', data)
  },
  // 设置代理选择模式
  setAgentSelectModel({ commit }, data) {
    commit('SET_AGENT_SELECT_MODEL', data)
  },
  // 清空代理-全部清空
  cleanAgent({ commit }) {
    commit('CLEAN_AGENT')
  },
  // 清空代理-选中数据
  cleanAgentData({ commit }) {
    commit('CLEAN_AGENT_DATA')
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

